<template>
	<!--
	    author: 李文昊
	    conListLeft: 左边导航栏组件，这里把右边内容写在了这个组件里面
	-->
	<view class="list-content">
		<con-list-left v-if="flag" ref="listRoom" :floorList="floorListBak"></con-list-left>
	</view>
</template>

<script>
	import {
		ONLINE_SERVER_ADDRESS_BASE,
	} from "../../../util/network.js"
	export default {
		data() {
			return {
				token:'',
				floorList: [],
				floorListBak:[],
				flag:false,
			}
		},
		methods:{
			async loadImg(chargeFileId){
				// let _this = this
				const res = await uni.downloadFile({
					url:`${ONLINE_SERVER_ADDRESS_BASE}/file/download/` + chargeFileId,
					header: {
						'Authorization': this.token,
					},
				})
				return new Promise((resolve, reject) => {
				        resolve(res[1].tempFilePath)
				})
			},
			preLoad(roomList){
				let maxFloor = this.getMaxFloor(roomList)
				this.floorListBak = new Array(maxFloor)
				this.floorListBak[0] = {id: 0,floorName: "全部楼层",img: []}
				for (var i = 1; i < maxFloor; i++) {
					let temp = {'id':i, 'floorName':(i + '楼'), 'img':[]}
					this.floorListBak[i] = temp
				}
				console.log("楼盘会议室",this.floorListBak)
				roomList.forEach(item => {
					let curFloor = parseInt(item.floor)
					let temp = {'id':item.id,'name':item.houseNo,'imgUrl':'', 'roomType':''}
					temp.imgUrl = ONLINE_SERVER_ADDRESS_BASE + '/file/thumbnail-preview/' + item.picture.split(',')[0]
					if(item.specification == 0) temp.roomType = "小"
					if(item.specification == 1) temp.roomType = "中"
					if(item.specification == 2) temp.roomType = "大"
					this.floorListBak[curFloor].img.push(temp)
				})
				let index = 1
				while(index != this.floorListBak.length){
					if(this.floorListBak[index].img.length == 0){
						this.floorListBak.splice(index,1)
					}else{
						index = index + 1
					}
				}
				this.$set(this.floorList,this.floorListBak)
				this.flag = true
				console.log("楼盘会议室2",this.floorListBak)
			},
			getMaxFloor(roomList){
				let maxFloor = 0
				roomList.forEach(item => {
					if(maxFloor < parseInt(item.floor)){
						maxFloor = parseInt(item.floor)
					}
				})
				return maxFloor + 1
			},
			getMeetingRoomList(){
				let _this = this
				let buildId = uni.getStorageSync("userinfo").buildId
				uni.request({
					url:`${ONLINE_SERVER_ADDRESS_BASE}/meeting-room/build/` + buildId,
					header: {
						'Authorization': this.token,
					},
					method:'GET',
					success: function (res) {
						console.log("查询会议室",res);
						if(res.data.code == 200){
							_this.preLoad(res.data.data)
							// _this.$refs.listRoom.father(0)
						}
					},
					fail: (res) => {
						console.log("查询会议室失败")
					}
				})
			}
		},
		onShow() {
			this.token = uni.getStorageSync('token')
			this.getMeetingRoomList()
		}
	}
</script>

<style>
	/* 左右内边距，保证文档流正常 */
	.list-content {
		padding-left: 25%;
		padding-right: 20rpx;
	}
</style>
